package com.hysoft.cxf.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hysoft.cxf.po.Cat;
import com.hysoft.cxf.po.User;
import com.hysoft.cxf.service.UserService;
import com.hysoft.cxf.ws.utils.StringCat;
import com.hysoft.cxf.ws.utils.StringCat.Entry;

public class UserServiceImpl implements UserService {
	static List<User> userdb = new ArrayList<>();
	
	static Map<String, List<Cat>> db = new HashMap<String, List<Cat>>();
	
	static {
		
		User user1 = new User(1,"孙悟空","花果山");
		User user2 = new User(2,"猪八戒","高老庄");
		userdb.add(user1);
		userdb.add(user2);
		
		List<Cat> list1 = new ArrayList<Cat>();
		Cat cat1 = new Cat(1,"机器猫","蓝色");
		Cat cat2 = new Cat(2,"加菲猫","黄色");
		list1.add(cat1);
		list1.add(cat2);
		db.put("wukong", list1);
		
		List<Cat> list2 = new ArrayList<Cat>();
		Cat cat3 = new Cat(3,"kitty猫","白色");
		Cat cat4 = new Cat(4,"熊猫","黑白色");
		list2.add(cat3);
		list2.add(cat4);
		db.put("bajie", list2);
		
	}
	
	@Override
	public List<Cat> getCatsByUser(String username) {
		return db.get(username);
	}

	@Override
	public Map<String, Cat> getAllCats() {
		Map<String, Cat> map = new HashMap<String, Cat>();
		int i = 1; 
		for (List<Cat> cats : db.values()) {
			for (Cat cat : cats) {
				map.put("第" + i + "只", cat);
				i++;
			}
		}
		return map;
	}

	@Override
	public StringCat getStringCat() {
		StringCat stringCat = new StringCat();
		int i = 1; 
		List<Entry> entries= new ArrayList<>();
		for (List<Cat> cats : db.values()) {
			for (Cat cat : cats) {
				entries.add(new Entry("第" + i + "只", cat));
				i++;
			}
		}
		stringCat.setEntries(entries);
		return stringCat;
	}

}
